<?php
/**
 * Created by PhpStorm.
 * User: xlosy
 * Date: 2018/4/14
 * Time: 10:35
 */

namespace app\admin\controller;

use app\index\model\User;
use think\Controller;
use think\Request;

/**
 * 基类控制器
 * Class Base
 * @package app\manager\controller
 */
class Base extends Controller{

    public function _initialize(){
        $request = Request::instance();
        define("BASE_PATH",$request->domain());
        $requestInfo = $request->module()."/".$request->controller()."/".$request->action();
        $isM = session('isM');
        $uid = session('AdminUId');
        $access_name = $isM;
        if($access_name==null && $uid ==null){
            $access_name = $request->action();
            $user = new User();
            $user->where('userName',$access_name);
            $user->where('isManager',"1");
            $user_db = $user ->find();
            if($user_db==null){
                $this->redirect('/');
            }
        }

        if($uid== null){
            if($requestInfo=="admin/Manager/".$access_name){
                if($uid== null || $isM ==null){
                    session('isM',$access_name);
                    $this->redirect('Adminverification/loginInput');
                }else{
                    $this->redirect('Manager/film_list');
                }
            }else if($isM == null){
                $this->redirect('/');
            }
        }else{
            if($isM!=null){
                session('isM',null);
            }
            if($requestInfo=="admin/Manager/".$uid->userName){
                $this->redirect('Manager/film_list');
            }
        }
    }
}